﻿using MySql.Data.MySqlClient;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace DataAccessService.IService
{
    public interface IMySqlService
    {
        /// <summary>
        /// 获取mysql连接
        /// </summary>
        /// <returns></returns>
        MySqlConnection GetConn();

        /// <summary>
        /// 执行SQL请求
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        DataSet QuerySQL(string sql);

        /// <summary>
        /// 获取实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <returns></returns>
        T GetItem<T>(string sql);

        /// <summary>
        /// 获取实体集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="sql"></param>
        /// <returns></returns>
        List<T> GetList<T>(string sql);

        /// <summary>
        /// 新增实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item"></param>
        /// <param name="idField">id字段</param>
        /// <returns></returns>
        bool Add<T>(T item, string idField);

        /// <summary>
        /// 新增实体集合
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="items"></param>
        /// <param name="idField">id字段</param>
        /// <returns></returns>
        bool AddItems<T>(List<T> items,string idField);

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="item"></param>
        /// <param name="id"></param>
        /// <returns></returns>
        bool Update<T>(T item,string field,string value);

        /// <summary>
        /// 执行语句
        /// </summary>
        /// <param name="sql"></param>
        /// <returns></returns>
        bool ExcuteSQL(string sql);
    }
}
